<!-- 激励活动 -->
<template>
	<view>
		<view class="head">
			<view class="title">激励活动</view>
			<view class="desc">准备好挑战奖金了吗？</view>
		</view>
		<view class="tit">活动列表</view>
		<view class="list u-p-b-60">
			<view class="item"
				v-for="(item,index) in list"
				:key="item.id"
				@click="$Router.push({ path: '/pages/index/actuate/detail', query: { id: item.id } })">
				<view class="title">{{item.title}}</view>
				<view class="desc">{{item.richtext_title}}</view>
				<view class="time">报名时间：{{item.sign_starttime_text_d}} 至 {{item.sign_endtime_text_d}}</view>
				<view class="time">活动时间：{{item.starttime_text_d}} 至 {{item.endtime_text_d}}</view>
				<view class="tags">
					<view v-for="(tag,tagIndex) in item.tags_list"
						:key="tagIndex"
						class="tag">{{tag}}</view>
				</view>
				<view class="extra u-flex "
					v-if="item.status != 'nostart' && item.sign_status == 'signed'">
					<view class="u-flex-1">
						<progress :percent="item.percent"
							:style="{width:'100%'}"
							active-color="#ed6328"></progress>
					</view>
					<view class="u-m-l-30">{{item.complete_order_count}}/{{item.order_count}}单</view>
				</view>
				<view class="extra">
					<view class="u-flex u-row-center">
						<view>奖金：</view>
						<view class="price"> {{item.reward}}<text>元</text></view>
					</view>
					<view class="btn"
						v-if="item.sign_status == 'ing'">立即报名</view>
					<view class="status"
						v-else-if="item.sign_status == 'nostart' || item.status == 'nostart'">{{item.sign_status_text}}
					</view>
					<template v-else-if="item.status == 'ended' && item.sign_status == 'signed'">
						<view class="btn" v-if="item.receive_status == 0"
						@click.stop="receiveReward(index)">
							领取奖金
						</view>
						<view class="status" v-else>{{item.receive_status_text}}</view>
					</template>
					<view class="status"
						v-else
						:class="{'disabled':item.status == 'ended'}">{{item.status_text}}</view>
				</view>
			</view>
			<view style="height: 20rpx;"></view>
			<!-- 更多 -->
			<u-loadmore v-show="!isEmpty"
				height="80rpx"
				:status="loadStatus"
				icon-type="flower"
				color="#ccc" />
			<!-- 空置页 -->
			<shopro-empty v-if="isEmpty"
				marginTop="300rpx"
				:image="$IMG_URL + '/imgs/empty/no_data.png'"
				tipText="暂无数据~"></shopro-empty>
		</view>
		<!-- #ifdef H5 -->
		<!-- <view class="tabbar-hack"
			style="height: 120rpx; width:100%;"></view> -->
		<!-- #endif -->
	</view>
</template>
<script>
	export default {
		components: {},
		data() {
			return {
				list: [],
				loadStatus: 'loadmore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
				currentPage: 1,
				lastPage: 1,
				isEmpty: false
			};
		},
		computed: {},
		filters: {
			applyInfoFilter: function(value) {
				if (!value) return '-';
				return Object.values(value).join(' | ');
			}
		},
		onLoad() {
			this.getList();
		},
		// 触底加载更多
		onReachBottom() {
			if (this.currentPage < this.lastPage) {
				this.currentPage += 1;
				this.getList();
			}
		},
		methods: {
			// 领取奖励
			receiveReward(index){
				let that = this
				uni.showLoading()
				that.$http('activity.receiveReward', {
					activity_id: that.list[index].id
				}).then(res => {
					uni.hideLoading()
					if (res.code === 1) {
						Object.assign(that.list[index],res.data)
					}
				});
			},
			getList() {
				let that = this;
				that.loadStatus = 'loading';
				that.$http('activity.list', {
					page: that.currentPage
				}).then(res => {
					if (res.code === 1) {
						that.list = [...that.list, ...res.data.data];
						that.isEmpty = !that.list.length;
						that.lastPage = res.data.last_page;
						that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
					}
				});
			}
		}
	};
</script>
<style lang="scss">
	.tit {
		font-size: 34rpx;
		font-weight: 900;
		margin: 50rpx 0;
		padding: 0 40rpx;
		padding-left: 40rpx;
		position: relative;
	}

	.tit::before {
		content: '';
		height: 100%;
		width: 8rpx;
		position: absolute;
		left: 10rpx;
		top: 0%;
		background: #e6d19a;
		border-radius: 20rpx;
	}

	.head {
		background: #e6d19a;
		padding: 60rpx;
		border-bottom-left-radius: 60rpx;
		border-bottom-right-radius: 60rpx;
		font-weight: 900;
		color: #fff;
		font-size: 36rpx;

		.title {
			font-size: 50rpx;
			padding-bottom: 20rpx;
		}
	}

	.list {
		padding: 0 20rpx 20rpx;
		margin-top: -20rpx;

		.item {
			padding: 30rpx;
			border-bottom: 1px solid #f7f7f7;
			background: #fff;
			margin: 20rpx 0;
			border-radius: 10rpx;

			.title {
				font-size: 32rpx;
				font-weight: 900;
			}

			.desc {
				color: #828282;
				margin-top: 16rpx;
			}

			.time {
				color: #333;
				margin-top: 16rpx;
			}

			.tags {
				margin-top: 20rpx;

				.tag {
					display: inline-block;
					background: #dae9cc;
					color: #5db867;
					margin-right: 16rpx;
					padding: 2rpx 6rpx;
					font-size: 26rpx;
					border-radius: 10rpx;
				}
			}

			.extra {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 20rpx;
				color: #828282;

				.price {
					font-size: 36rpx;
					font-weight: 900;
					color: #f26161;

					text {
						font-size: 80%;
					}
				}

				.status {
					display: inline-block;
					color: #0c7b92;

					&.disabled {
						color: #cccccc;
					}
				}

				.btn {
					display: inline-block;
					padding: 10rpx 20rpx;
					border-radius: 10rpx;
					background: #d8e6fa;
					color: #0c7b92;

					&.disabled {
						background: #f4f4f4;
						color: #cccccc;
					}
				}
			}
		}
	}
</style>